<script language="javascript">
    $(document).ready(function(){
        $('#change_password').click(function(){
            $('.password_form').fadeIn(200);
        });
    
        $('#ModeratorChangePasswordForm').live('submit',function(){
            var pass1=$('#new_pass').val();
            var pass2=$('#cnfrm_pass').val();
            if($('#old_pass').val().length<1){
                 $('.error-message').css('display','block');
                 $('.error-message').text('Enter old Password.').delay(900).fadeOut(2000);
                 return false;
            }
            if(pass1!=pass2){
                 $('.error-message').css('display','block');
                 $('.error-message').text('Passwords Do not Match.').delay(900).fadeOut(2000);
                return false;
            }
            else if(pass1.length<1){
                 $('.error-message').css('display','block');
                $('.error-message').text('New Password field is empty.').delay(900).fadeOut(2000);
                return false;
            }
            else{
            
                $.ajax({
                    url:'change_password' ,
                    type:'POST',
                    data:{old_pass:$('#old_pass').val(),new_pass:pass1},
                    success:function(response){
                        if(response){
                            
                            $('.password_form').fadeOut(50);
                            
                            $('.success').text('Password Changed. Login Next time with your new password').fadeIn(200).delay(2000).fadeOut(5000);
                           
                            
                        }else{
                            $('.error-message').css('display','block');
                             $('.error-message').text('The Old password you provided do not match to our database.').delay(1200).fadeOut(2000);
                             return false;
                        }
                    }
                });
            }
             return false;   
            });       
         
    });
</script>

<table width="100%" border="0" cellspacing="0" cellpadding="0" >
    <tr valign="top">
        <td width="26%" ><div><?php
if (!empty($user['UserProfile']['image'])) {
    $thumbnail = $this->PhpThumb->generate(
            array(
                'save_path' => WWW_ROOT . 'img/uploads/Moderators/thumbs',
                'display_path' => 'uploads/Moderators/thumbs',
                'error_image_path' => 'error.png',
                'src' => WWW_ROOT . "img/uploads/Moderators/" . $user['UserProfile']['image'],
                'w' => 250,
                'h' => 250,
                'q' => 100,
                'zc' => 1
            )
    );

    //echo $this->Html->image($thumbnail['src'], array('width' => $thumbnail['w'], 'height' => $thumbnail['h'], 'class' => 'display-image'));
    echo $this->Html->image("uploads/Moderators/".$user['UserProfile']['image'], array('width' => 250, 'height' => 250, 'class' => 'display-image'));//K
} else {
    echo $this->Html->image('noimage.png', array('width' => '250', 'height' => '250', 'class' => 'display-image'));
}
?>
            </div>
            <div class="clearfix"></div>
            <div id="change_password" class="mybutton" style="width:102px;">Change Password</div>
            <div class="clearfix"></div>
            <div class="success" style='display:none;'></div>
            <div style='display:none;padding: 5px;' class="password_form">
<?php
echo $this->Form->create('Moderator', array('action' => 'change_password'));
echo $this->Form->input('old_pass', array('label' => 'Old Password', 'type' => 'password','id'=>'old_pass'));
echo $this->Form->input('User.password', array('label' => 'New Password', 'id' => 'new_pass'));
echo $this->Form->input('confirm_pass', array('label' => 'Confirm Password', 'type' => 'password', 'id' => 'cnfrm_pass'));
echo "<div class='error-message'></div>";
echo $this->Form->end(array('label' => 'Save', 'class' => 'mybutton'));
?>

            </div>
        </td>
        <td width="74%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td><div class="content-arae">
                            <h1><?php echo $user['UserProfile']['screenname'] ?></h1>
<?php if ($this->Access->check('Subject', 'create')): ?>
                                <ul class="listing-menu-1">
                                    <li>HAS: <span><?php if (isset($_SESSION['points']))  __($_SESSION['points']); else __('0'); ?> Points </span> </li>
                                    <li>RATED: <span><?php __(count($user['SubjectRate']) . " Subjects") ?></span> </li>
                                    <li>ADDED: <span><?php __(count($user['Subject']) . " Subjects"); ?></span></li>
                                </ul>
                            <?php endif; ?>
                        </div><span  style="float: right;"><?php echo $this->Html->link('Edit', array('action' => 'admin_edit', $user['User']['id']), array('class' => 'mybutton')); ?></span>
                    </td>
                </tr>
                <tr>
                    <td><table width="100%" border="0" cellspacing="0" cellpadding="0" class="side-table">
                            <tr  class="bgcolor">
                                <td width="36%"><strong>Full Name:</strong></td>
                                <td><?php echo $user['UserProfile']['first_name'] . "  " . $user['UserProfile']['last_name'] ?></td>
                            </tr>
                            <tr>
                                <td><strong>Login Name:</strong></td>
                                <td><?php echo $user['User']['username'] ?></td>
                            </tr>
                            <tr class="bgcolor">
                                <td><strong>Screen Name:</strong></td>
                                <td><?php echo $user['UserProfile']['screenname'] ?></td>
                            </tr>
                            <tr>
                                <td><strong>Email:</strong></td>
                                <td><?php echo $user['User']['email'] ?></td>
                            </tr>
                            <tr class="bgcolor">
                                <td><strong>Alternative Email:</strong></td>
                                <td><?php echo $user['UserProfile']['alt_email'] ?></td>
                            </tr>
                            <tr>
                                <td><strong>DOB:</strong></td>
                                <td><?php echo $user['UserProfile']['dob'] ?></td>
                            </tr>
                            <tr  class="bgcolor">
                                <td><strong>Gender:</strong></td>
                                <td> <?php echo $user['UserProfile']['sex'] ?></td>
                            </tr>
                            <tr>
                                <td><strong>Religion:</strong></td>
                                <td><?php echo $user['UserProfile']['religion'] ?></td>
                            </tr>
                        </table></td>
                </tr>

            </table></td>
    </tr>
</table>
